package com.qf.servlet;

import com.qf.entity.Student;
import com.qf.service.StuService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * description:
 * author: Ken
 * 公众号：Java架构栈
 */
@WebServlet(urlPatterns = "/stuinsert")
public class StudentInsertServlet extends HttpServlet {

    private StuService stuService = new StuService();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取新增学生的参数
        String name = req.getParameter("name");
        String sex = req.getParameter("sex");
        String cid = req.getParameter("cid");

        //封装实体类
        Student student = new Student()
                .setName(name)
                .setSex(Integer.parseInt(sex))
                .setCid(Integer.parseInt(cid));

        //调用学生业务层 添加学生
        stuService.insertStus(student);

        //跳转到学生列表的servlet
        resp.sendRedirect("stuquery");
    }
}
